package <%= beanInfo.package %>.dao;

import <%= beanInfo.package %>.core.Pager;
import <%= beanInfo.package %>.entity.<%= beanInfo.classname %>;
import <%= beanInfo.package %>.core.jdbc.SimpleDao;
import <%= beanInfo.package %>.core.jdbc.sql.SqlType;
import <%= beanInfo.package %>.core.jdbc.trans.Trans;
import <%= beanInfo.package %>.core.jdbc.trans.Atom;


import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Created with ruby.
* User:
* Date: <%= beanInfo.date %>
*/
@Component
public class <%= beanInfo.classname %>Dao extends SimpleDao<<%= beanInfo.classname %>, Long> {

    private static Logger logger = Logger.getLogger(<%=beanInfo.classname%>Dao.class);

    public Pager findPager(<%=beanInfo.classname%>  <%=beanInfo.alias%>, Pager pager){
        List paramList = new ArrayList();
        StringBuilder sql = new StringBuilder("select * from <%=beanInfo.tablename%> where 1=1");
        /*  //查询条件
        if (StringUtils.isNotBlank(project.getProjectName())) {
        sql.append(" and projectName like concat('%',?,'%')");
        paramList.add(project.getProjectName());
        }*/
        Object[] params = (paramList.size() > 0) ? paramList.toArray() : null;
        return getPager(pager, sql.toString(), params);
    }

     public Pager findPagerMap(<%=beanInfo.classname%>  <%=beanInfo.alias%>,Pager pager){
            List paramList = new ArrayList();
            StringBuilder sql = new StringBuilder("select * from  <%=beanInfo.tablename%>");

            //查询条件
            /*if (StringUtils.isNotBlank(user.getName())) {
                sql.append(" and name like concat('%',?,'%')");
                paramList.add(user.getName());
            }*/
            Object[] params = (paramList.size() > 0) ? paramList.toArray() : null;
            return getPagerMap(pager, sql.toString(), params);
        }

    public List<<%= beanInfo.classname %>> find() {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from <%= beanInfo.tablename %>");
        return find(sql.toString());
    }

    public <%= beanInfo.classname %> get(Long id) {
        String sql = "select * from <%= beanInfo.tablename %> where id=?";
        return get(sql, id);
    }


    public Atom save(<%= beanInfo.classname %> <%= beanInfo.alias %>) {
        Atom atom = executeEntity(<%= beanInfo.alias %>, SqlType.Insert);
        Trans.exec(atom);
        return atom;
     }

      public void update(<%= beanInfo.classname %> <%= beanInfo.alias %>) {
             Atom atom = executeEntity(<%= beanInfo.alias %>, SqlType.Update);
             Trans.exec(atom);
      }

      public void deleteById(Long id) {
             String sql = "delete from <%= beanInfo.tablename %>  where id=?";
             Trans.exec(execute(sql, id));
       }


}
